#pragma once
// linux head file 
#include <pthread.h>
// c++ head file
#include <string>
#include <memory>
#include <fstream>
#include <unordered_map>
#include <mutex>
#include <condition_variable>

// extern 声明
extern std::mutex gnss_data_mutex;
extern std::condition_variable gnss_data_cv;
extern struct gnss_data gnss_latest_data;

extern std::mutex sonar_data_mutex;
extern std::condition_variable sonar_data_cv;
extern struct sonar_data sonar_latest_data;


// 定义结构体
struct start_para{
  public:
    start_para():sensor_list_(),run_mode_(0),file_num_(-1){};
    std::unordered_map<std::string, int> sensor_list_;
    int run_mode_;                           //运行模式
    int file_num_;                           //目录编号
    std::unique_ptr<std::ofstream> p_ofs_;   //输出文件流
};

class SensorAbstraction
{
private:
    pthread_attr_t attr_;                                         //线程属性结构体
    sched_param param_;                                           //线程参数结构体
    /* data */
public:
    SensorAbstraction(const std::string& sensor_name_,const int& run_mode_);
    virtual ~SensorAbstraction();

    int Run();
    void ThreadInit(int sche_algo,int pth_priority);
    void StartThread();    

    virtual int Init() = 0;
    virtual int DataCollection() = 0;                             //传感器数据采集
    virtual int DataProcessing() = 0;                             //传感器数据处理
    virtual int DataStorage() = 0;                                //传感器数据储存
    virtual int DataPrint() = 0;

    pthread_t tid;       
    std::string sensor_name;
    int run_mode;
    static bool RunOK;  
};

//初始化系统
std::shared_ptr<start_para> InitSystem(int argc,char** argv);
//启动系统
void StartSystem(std::shared_ptr<start_para> p_start_para);
